package com.qf.service.impl;

import com.qf.dao.AccountDao;
import com.qf.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/*
 *@Description:
 *@author:刘哥
 *@Date:10:01 2022/7/12
 */

@Component
public class AccountServiceImpl implements AccountService {
    @Autowired//dao注入
    @Qualifier("accountDao")//按照名称注入
    private AccountDao accountDao;
//    public void setAccountDao(AccountDao accountDao){
//        this.accountDao=accountDao;
//    }
// 事务              默认配置                                传播行为                    事务等待时间      可读写:false(默认)可读可写,true()只读;   回滚得条件
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,timeout = -1,readOnly = false,rollbackFor = Exception.class)//事务注解，在这个方法及定位了
    @Override
    public void transfer(String cardNo, String toCardNo, BigDecimal money) {
        //我卡扣钱
        accountDao.minusUpdate(cardNo,money);
        int i=10/0;
        //对方卡加钱
        accountDao.plusUpdate(toCardNo,money);
    }
}
